package interaction.sampling.matching;

import interaction.sampling.Sample;
import interaction.sampling.SampleSet;
import interaction.sampling.Samples;

/**
 * Gives a measure on how often bands in the fft spectrum of a test sample are
 * present in the average fft spectrum obtained from a set of comparison
 * samples.
 */
public class SpectrumMatcher implements Matcher {
	private static final float TRESHOLD = 1;
	
	public double match(Sample test, SampleSet comparison) {
		Sample average = comparison.getSampleAverage();
		double rating = 0;
		int max = Samples.getMaximumSize(test, average);
		for (int i = 0; i < max; i++) {
			boolean testHasSpectrum = test.get(i) > TRESHOLD;
			boolean averageHasSpectrum = average.get(i) > TRESHOLD;
			if (testHasSpectrum && averageHasSpectrum) {
				rating++;
			} else if (testHasSpectrum || averageHasSpectrum) {
				rating--;
			}
		}
		return rating / test.size();
	}

	public double getAcceptanceTreshold() {
		return -0.1;
	}

}
